<?php if (SET != 1) die(); ?>
	
<?php
		
			if (file_exists(config("root")."data/users.xml")) {

				$xmlObj = simplexml_load_file(config("root")."data/users.xml");

				$usersObj = $xmlObj->xpath("user/id[text()='".$_GET['id']."']/..");
				
				if ($usersObj) {
					
					$usersObj[0]->active = "1";
					
					$save = file_put_contents(config("root")."data/users.xml", $xmlObj->asXML());
			
					if ($save !== false) {
						
						/* send mail */

						include_once("../../global/phpmailer/class.phpmailer.php");

				        $mail = new PHPMailer();

				        //$mail->CharSet  =  "iso-8859-1";
				        $mail->Timeout = "60";

				                      $mail->IsSMTP();
				                      $mail->Host = config("mail_host");

				                      $mail->SMTPAuth = config("mail_auth");
				                      $mail->Username = config("mail_username");
				                      $mail->Password = config("mail_password");

				        $mail->From = config("mail_from");

				        $mail->FromName = config("mail_from_name");

				        $mail->AddAddress(utf8_decode(xmldecode($usersObj[0]->email)));

				        $mail->Subject = "Registrierung abgeschlossen";

							$mailtemplate = utf8_decode(file_get_contents(config("root")."data/mailtemplate_activate.txt"));
							$mailtemplate = str_replace("#forename#", utf8_decode(xmldecode($usersObj[0]->forename)), $mailtemplate);
							$mailtemplate = str_replace("#name#", utf8_decode(xmldecode($usersObj[0]->name)), $mailtemplate);
							$mailtemplate = str_replace("#username#", utf8_decode(xmldecode($usersObj[0]->username)), $mailtemplate);

				        $mail->Body = $mailtemplate;

				        $send = $mail->Send();

						if ($send) {

							echo '
								<p class="success">Der Benutzer wurde freigeschaltet</p>
								<meta http-equiv="refresh" content="1; url=index.php?m=users&f=users" />
							';

						} else {
							error("Fehler beim Versenden der E-Mail");
						}
						
					} else error("Fehler beim Speichern der XML-Datei");
			
				} else error("Das Benutzerkonto wurde nicht gefunden");
			
			} else error("Benutzerliste nicht gefunden");
			
?>
	